from django.utils.decorators import method_decorator

from gis.admin.decorators import require_login, check_permission
from gis.common.django_ext.decorators import validate_parameters
from gis.common.django_ext.views import BaseView
from itpay.core.admin_ext.service import get_admin_account_by_id, update_admin_account
from .admin_forms import UpdateAdminAccountSchema


class AdminAccountDetailView(BaseView):
    @method_decorator(require_login)
    @method_decorator(check_permission('admin_user_get'))
    def get(self, account_id):
        return get_admin_account_by_id(account_id)

    @method_decorator(require_login)
    @method_decorator(check_permission('admin_user_update'))
    @method_decorator(validate_parameters(UpdateAdminAccountSchema))
    def put(self, account_id, cleaned_data):
        update_admin_account(account_id, **cleaned_data)
        return dict(id=account_id)
